﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MediaPortal.GUI.Library;

namespace Burn4You
{
    public class ProgressScreen : GUIWindow
    {
        #region Skin Controls

        [SkinControlAttribute(10)]   protected GUIProgressControl ProgressBar;
        [SkinControlAttribute(3)]   protected GUIButtonControl btnClose;
        [SkinControlAttribute(2)]        protected GUIButtonControl btnCancel;


        #endregion

        #region Variables

        Object CallingObject = null;

        #endregion

        #region MediaPortal Overrides

        public override bool Init()
        {
            GUIWindowManager.Receivers += new SendMessageHandler(GUIWindowManager_Receivers);
            return Load(GUIGraphicsContext.Skin + @"\Burn4YouProgressScreen.xml");
        }

        void GUIWindowManager_Receivers(GUIMessage message)
        {
            if (message.Label == "Calling Object")
            {
                CallingObject = message.Object;
                if (CallingObject.GetType() == typeof(EncoderHelper))
                {
                    ((EncoderHelper)CallingObject).EncoderUpdateEvent += new EncoderHelper.EncoderUpdateHandler(ProgressScreen_EncoderUpdateEvent);
                }
            }
        }

        void ProgressScreen_EncoderUpdateEvent(EncoderUpdate update)
        {
            ProgressBar.Percentage = update.PercentageComplete;
            //Utils.Burn4YouLog.Write("Encoder Progress Window: Received update: " + update.PercentageComplete.ToString());
        }

        public override int GetID
        {
            get
            {
                return 54266;
            }
        }

        protected override void OnPageLoad()
        {
            base.OnPageLoad();
        }

        protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType)
        {
            if(control == btnClose)
            {
                GUIWindowManager.ShowPreviousWindow();
            }
            else if (control == btnCancel)
            {    
                Burn4YouPlugin.MediaEncoderHelper.Stop();
            }

            base.OnClicked(controlId, control, actionType);
        }

        #endregion

        #region Public Properties

        #endregion

        #region Functions

        #endregion
    }
}
